;*******************************************************************************
; (C) 2006 Keith S. Robertson - IE_KEY.ASM
;-------------------------------------------------------------------------------
;
; All Infinity Engines Functions, Variables & Data Related to KEY Format Files
;
;*******************************************************************************
.386	

INCLUDE IE.MAC	; Macros
INCLUDE masm32.inc

INCLUDELIB masm32.lib

.CONST

.DATA

	
.DATA?
__hKEYFileHandle	DD	?	; IE KEY File Handle

.CODE

KEYOpenFile				PROC 	KEYFileName:DWORD
	Invoke IEOpenFile, KEYFileName
	ret
KEYOpenFile 			ENDP


KEYCloseFile 			PROC 	hKEYFile:DWORD
	Invoke IECloseFile,hKEYFile
	ret
KEYCloseFile 			ENDP


KEYNoBifEntries 		PROC	hFile_or_pMem:DWORD, pBuffer:DWORD, AccessType:DWORD
	LOCAL hFile:DWORD
	LOCAL pMem:DWORD
	LOCAL lnBytesRead:DWORD	
		
	mov eax, hFile_or_pMem
	
	.IF AccessType == KEY_ACCESS_FILE	; 0 
		mov hFile, eax
		Invoke SetFilePointerEx, hFile, 8, NULL, NULL, FILE_BEGIN
		Invoke ReadFile, hFile, pBuffer, 4, addr lnBytesRead, NULL
		.if eax != 0
			mov eax, TRUE
		.else
			mov eax, FALSE
		.endif
		
	.else	; KEY_ACCESS_MEM ; 1
		mov pMem, eax
		lea ebx, pMem
		add ebx, 8
		Invoke MemCopy, pBuffer, ebx, 4
		mov eax, TRUE
	.endif
	ret

	ret
KEYNoBifEntries 		ENDP


KEYNoResEntries 		PROC	hFile_or_pMem:DWORD, pBuffer:DWORD, AccessType:DWORD
	LOCAL hFile:DWORD
	LOCAL pMem:DWORD
	LOCAL lnBytesRead:DWORD	
		
	mov eax, hFile_or_pMem
	
	.IF AccessType == KEY_ACCESS_FILE	; 0 
		mov hFile, eax
		Invoke SetFilePointerEx, hFile, 12, NULL, NULL, FILE_BEGIN
		Invoke ReadFile, hFile, pBuffer, 4, addr lnBytesRead, NULL
		.if eax != 0
			mov eax, TRUE
		.else
			mov eax, FALSE
		.endif
		
	.else	; KEY_ACCESS_MEM ; 1
		mov pMem, eax
		lea ebx, pMem
		add ebx, 12
		Invoke MemCopy, pBuffer, ebx, 4
		mov eax, TRUE
	.endif
	ret
KEYNoResEntries ENDP


KEYBifEntriesOffset		PROC	hFile_or_pMem:DWORD, pBuffer:DWORD, AccessType:DWORD
	LOCAL hFile:DWORD
	LOCAL pMem:DWORD
	LOCAL lnBytesRead:DWORD	
		
	mov eax, hFile_or_pMem
	
	.IF AccessType == KEY_ACCESS_FILE	; 0 
		mov hFile, eax
		Invoke SetFilePointerEx, hFile, 16, NULL, NULL, FILE_BEGIN
		Invoke ReadFile, hFile, pBuffer, 4, addr lnBytesRead, NULL
		.if eax != 0
			mov eax, TRUE
		.else
			mov eax, FALSE
		.endif
		
	.else	; KEY_ACCESS_MEMORY ; 1
		mov pMem, eax
		lea ebx, pMem
		add ebx, 16
		Invoke MemCopy, pBuffer, ebx, 4
		mov eax, TRUE
	.endif
	ret
KEYBifEntriesOffset 	ENDP


KEYResEntriesOffset		PROC	hFile_or_pMem:DWORD, pBuffer:DWORD, AccessType:DWORD
	LOCAL hFile:DWORD
	LOCAL pMem:DWORD
	LOCAL lnBytesRead:DWORD	
		
	mov eax, hFile_or_pMem
	
	.IF AccessType == KEY_ACCESS_FILE	; 0 
		mov hFile, eax
		Invoke SetFilePointerEx, hFile, 20, NULL, NULL, FILE_BEGIN
		Invoke ReadFile, hFile, pBuffer, 4, addr lnBytesRead, NULL
		.if eax != 0
			mov eax, TRUE
		.else
			mov eax, FALSE
		.endif
		
	.else	; KEY_ACCESS_MEMORY ; 1
		mov pMem, eax
		lea ebx, pMem
		add ebx, 20
		Invoke MemCopy, pBuffer, ebx, 4
		mov eax, TRUE
	.endif
	ret
KEYResEntriesOffset 	ENDP



KEYBifEntry 			PROC	hFile_or_pMem:DWORD, pBuffer:DWORD, AccessType:DWORD
	ret
KEYBifEntry 			ENDP

KEYResEntry 			PROC 	hFile_or_pMem:DWORD, pBuffer:DWORD, AccessType:DWORD
	ret
KEYResEntry 			ENDP

KEYBifName 				PROC	hFile_or_pMem:DWORD, pBuffer:DWORD, AccessType:DWORD
	ret
KEYBifName 				ENDP	



